﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MG.HomeO2O.Model;

namespace MG.HomeO2O.DAL
{
    public class DetailDAL
    {
        EntityOP entity = new EntityOP();
        /// <summary>
        /// 显示内容信息
        /// </summary>
        /// <returns></returns>
        public List<Detail> ShowDetail()
        {
            return entity.Detail.ToList();
        }
        /// <summary>
        /// 根据编号显示内容信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Detail DetailGetid(int id)
        {
            return entity.Detail.Find(id);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteDetail(int id)
        {
            Detail ss = entity.Detail.Find(id);
            entity.Detail.Remove(ss);
            return entity.SaveChanges() > 0;
        }
        /// <summary>
        /// 添加内容信息
        /// </summary>
        /// <param name="ss"></param>
        /// <returns></returns>
        public int AddDetail(Detail ss)
        {
            entity.Detail.Add(ss);
            return entity.SaveChanges();
        }
        /// <summary>
        /// 修改内容信息
        /// </summary>
        /// <param name="ss"></param>
        /// <returns></returns>
        public int UpdateDetail(Detail ss)
        {
            entity.Entry(ss).State = System.Data.EntityState.Modified;

            return entity.SaveChanges();
        }
        /// <summary>
        /// 根据标题查询信息内容
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public List<Detail> SelectDetail(Detail s)
        {
            return entity.Detail.Where(p => (string.IsNullOrEmpty(s.Dtitle) ? true : p.Dtitle.Contains(s.Dtitle)) && (p.Cid == null ? true : p.Cid == s.Cid)).ToList();
        }
    }
}

